#ifndef DOCVIEW_H
#define DOCVIEW_H

#include <gtkmm.h>
#include "documents.h"
#include "filter.h"
#include "tagview.h"
#include "writingview.h"
#include "readingview.h"
#include "publisherview.h"

class PublisherView;
class WritingView;
class ReadingView;
class TagView;
class DocView : public Gtk::IconView
{
public:
    DocView();
    virtual ~DocView();
    void set_documents(sdms::documents* doc);
    void update();
    void update(const sdms::Filter*);
    void viewbook();
    void viewarticle();
    void viewnopdfdocument();
    virtual void add();
    virtual void add_folder();
    //virtual void insert_doc();
    virtual void showattribute();
    virtual void addtags();
    void set_tagview(TagView*);
    void set_writingview(WritingView*);
    void set_readingview(ReadingView*);
    void set_publisherview(PublisherView*);
    void set_statusbar(Gtk::Statusbar* s);
private:
    // Override Signal handler:
    // Alternatively, use signal_button_press_event().connect_notify()
    virtual bool on_button_press_event(GdkEventButton *ev);
    virtual bool on_button_release_event(GdkEventButton *ev);

    virtual void select_doc(const Gtk::TreeModel::Path& path);
    //bool get_thumb(Gtk::TreeModel::Row& row,const std::string fn);

    void _update(std::vector<sdms::document>& t);

    virtual void edit_doc(Gtk::TreeModel::Path& path,Gtk::CellRenderer*& cell);
    virtual void add_thumb();
    virtual void remove_doc();
    virtual void remove_all_doc();
    virtual void save_doc(const Glib::ustring& path_string, const Glib::ustring& new_text);
    virtual void datarender(Gtk::CellRenderer* , const Gtk::TreeModel::iterator& );
    //virtual Glib::RefPtr<Gdk::Pixbuf>  get_pixbuf(Gtk::TreeModel::Row& row,const std::string);
    virtual Glib::RefPtr<Gdk::Pixbuf>  get_pixbuf(const sdms::document& t);
    virtual void open_doc();
    virtual void remove_writing(unsigned int);
    virtual void remove_reading();
    virtual void add_reading();
    virtual void finish_reading();
    //virtual void remove_category(unsigned int);
    virtual void remove_tag(unsigned int);
    virtual void drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,   Gtk::SelectionData& selection_data, guint, guint);
    virtual void onSelectionChanged();
    virtual void onSaveEditing(const Glib::ustring& path_string, const Glib::ustring& new_text);
    virtual void onAddFolder(const std::string&);
    void edit_started(Gtk::CellEditable* editable, const Glib::ustring& path);
    void edit_done(Gtk::CellEditable* editable);
    void open_attachment(const std::string&);
    sigc::connection editconn,startconn,doneconn;
    //Tree model columns:
    class ModelColumns : public Gtk::TreeModel::ColumnRecord
    {
    public:
        ModelColumns()
        {
            add(id);
            add(name);
            add(click);
            add(pixbuf);
            add(uri);
        }

        Gtk::TreeModelColumn<unsigned int> id;
        Gtk::TreeModelColumn<unsigned int> click;
        Gtk::TreeModelColumn<Glib::ustring> name;
        Gtk::TreeModelColumn<Glib::ustring> uri;
        Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > pixbuf;
    };

    ModelColumns columns;

    //The Tree model:
    Glib::RefPtr<Gtk::ListStore> refListModel,nullList;

    Gtk::Menu menuPopup;
    Gtk::MenuItem removereadingMenu,removewritingMenu,removetagMenu;
    Gtk::MenuItem addreadingMenu;
    Gtk::MenuItem editdocMenu,attachMenu;
    Gtk::MenuItem addthumbMenu;
    Gtk::TreeView::Column doccolumn;
    bool editstatus;
    sdms::documents* mydoc;
    TagView* tagview;
    WritingView* writingview;
    ReadingView* readingview;
    PublisherView* publisherview;
    Gtk::Statusbar* status;
    std::list<Gtk::TreeModel::Path> old_selected;
    int mouse_x,mouse_y;
};

#endif
